<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <base href="<%=request.getContextPath()%>/">
  <meta charset="UTF-8">
  <title>新增预约</title>
  <link rel="stylesheet" href="statics/css/hisStyle.css">
  <style>
    .error-message {
      color: var(--danger);
      margin-bottom: 20px;
      padding: 12px 15px;
      background-color: #f8d7da;
      border: 1px solid #f5c6cb;
      border-radius: var(--border-radius);
    }
  </style>
</head>
<body>
<%@include file="../common/sidebar.jsp"%>
<div class="main-content">
  <%@include file="../common/top.jsp"%>
  <div class="content">
    <div class="card">
      <h2 class="section-title">新增预约</h2>

      <!-- 错误提示 -->
      <c:if test="${not empty error}">
        <div class="error-message">
            ${error}
        </div>
      </c:if>

      <form action="appointment/add" method="post">
        <div class="form-group">
          <label>患者姓名：</label>
          <input type="text" name="patientName" class="form-control" required>
        </div>
        <div class="form-group">
          <label>联系电话：</label>
          <input type="text" name="patientPhone" class="form-control" required>
        </div>
        <div class="form-group">
          <label>选择排班：</label>
          <select name="visitId" class="form-control" required>
            <option value="">-- 请选择排班 --</option>
            <c:forEach items="${departmentList}" var="dept">
              <c:set var="visits" value="${departmentVisitsMap[dept.deptId]}" />
              <c:if test="${not empty visits}">
                <optgroup label="${dept.deptName}">
                  <c:forEach items="${visits}" var="visit">
                    <option value="${visit.visitId}">
                      ${visit.doctorName} - ${visit.visitPeriod}
                    </option>
                  </c:forEach>
                </optgroup>
              </c:if>
            </c:forEach>
          </select>
        </div>
        <div class="form-group">
          <label>病情描述：</label>
          <textarea name="symptoms" class="form-control" rows="3"></textarea>
        </div>
        <div class="header-actions" style="justify-content: flex-start; margin-top: 30px;">
          <button type="submit" class="btn btn-primary">保存</button>
          <a href="appointment/find" class="btn btn-default" style="margin-left: 10px;">取消</a>
        </div>
      </form>
    </div>
  </div>
</div>
</body>
</html>